package com.tuniondata.netty.common;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.Arrays;

/**
 * @author yuxinchao
 */
public class Unpack {

    private String data;

    private Unpack(String data) {
        this.data = data;
    }

    public static Unpack alloc(byte[] data) {
        return new Unpack(new String(data));
    }

    public String string(int start, int len) throws IOException {
        return data.substring(start, len);
    }

    public byte[] read(int length) throws IOException {
        byte[] data = this.data.getBytes("GBK");

        return Arrays.copyOfRange(data, 0, length);
    }

    public String string(int len) throws IOException {
        return new String(read(len));
    }
}
